﻿using System;
using System.Collections.Generic;
using Castle.ActiveRecord;
using NoMiddleman.Core.Strategies;

namespace NoMiddleman.Core.Domain
{
    [ActiveRecord(DiscriminatorColumn = "Type", DiscriminatorType = "String" , DiscriminatorValue = "Advert")]
    public abstract class Advert
    {
        [PrimaryKey]
        public int Id { get; protected set; }

        [Property]
        public string Title { get; set; }

        [Property(Length = 2000)]
        public string Description { get; set; }

        [BelongsTo(Type = typeof(Client))]
        public Client Client { get; set; }

        [Property]
        public DateTime DateAdded { get; set; }

        [HasMany(typeof(Photo), Cascade = ManyRelationCascadeEnum.AllDeleteOrphan)]
        public IList<Photo> Photos { get; set; }

        [BelongsTo(Type = typeof(RealEstate))]
        public RealEstate RealEstate { get; set; }

        public decimal CalculateCost()
        {
            ICostCalculator calculator = CostCalculatorFactory.CreateCostCalculator(this);
            return calculator.CalculateCost(this);
        }
    }
}